package com.yangcangclub.trade.domain;

import com.google.common.collect.Maps;
import com.yangcangclub.commons.exception.ApolloException;
import com.yangcangclub.commons.result.MessageEnum;
import com.yangcangclub.trade.base.TradeBaseDomain;
import com.yangcangclub.trade.bean.TradeReqLogs;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by user on 2017/2/27.
 */
@Component
public class TradeReqLogsDomain extends TradeBaseDomain {

    public int insertTradeReqLogs(TradeReqLogs tradeReqLogs){
        super.getMasterJdbc().insert("trade.TradeReqLogsMapper.insertTradeReqLogs",tradeReqLogs);

        int id = tradeReqLogs.getId();
        if(id == 0){
            //回滚
            throw new ApolloException(MessageEnum.TRADE_REQ_LOG_ADD_FAILURE);
        }
        return id;
    }
    public boolean updateTradeReqLogsById(int id,int status){
        Map m = Maps.newHashMap();
        m.put("id",id);
        m.put("resultStatus",status);
        int num = super.getMasterJdbc().update("trade.TradeReqLogsMapper.updateTradeReqLogsById",m);
        if(num == 0){
            throw new ApolloException(MessageEnum.TRADE_REQ_LOG_UPDATE_FAILURE);
        }else{
            return true;
        }
    }

    public List<TradeReqLogs> selectTradeReqLogsByCondition(Map m){
        return super.getSlaveJdbc().selectList("trade.TradeReqLogsMapper.findTradeReqLogsByCondition",m);
    }


}
